using FineCollection.Intf;


namespace FineCollection.Immutable
{
    /// <summary>
    /// Immutable empty set. 
    /// </summary>
    /// <typeparam name="T">type of an item.</typeparam>
    public class ImmZero<T> : RSet<T>
    {


        #region CONSTRUCTOR

        internal ImmZero() {}


        /// <summary>
        /// An instance of empty set.
        /// </summary>
        public static readonly ImmZero<T> zero = 
            new ImmZero<T>();


        private static readonly IteratorOfZero<T> iteratorOfZero =
            new IteratorOfZero<T>();


        #endregion



        public bool IsEmpty
        {
            get { return true; }
        }

        public bool IsNotEmpty
        {
            get { return false; }
        }

        public int Count
        {
            get { return 0; }
        }

        public bool Contains(T item)
        {
            return false;
        }


        public RIterator<T> TakeIterator()
        {
            return iteratorOfZero;
        }


        System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator()
        {
            return iteratorOfZero;
        }


        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return iteratorOfZero;
        }



        #region ITERATOR CLASS

        internal class IteratorOfZero<TT> : RIterator<TT>,
                                            System.Collections.Generic.IEnumerator<TT>,
                                            System.IDisposable
        {
            public void Reset() {}

            public bool Next()  { return false; }

            public TT Current
            {
                get
                {
                    throw new CollectionIsEmpty();
                }
            }

            public sbyte Where
            {
                get { return +1; }
            }


            public RIterator<TT> Clone()
            {
                return this;
            }


            bool System.Collections.IEnumerator.MoveNext()
            {
                return false;
            }

            object System.Collections.IEnumerator.Current
            {
                get
                {
                    throw new CollectionIsEmpty();
                }
            }

            void System.IDisposable.Dispose()
            {
                // do nothing
            }


            public override string ToString()
            {
                return "empty iterator";
            }
        }

        #endregion



        public override string ToString()
        {
            return "{}";
        }
    }
}




